package com.bwie.parkdemo.mvvm.model.entity;

import com.bwie.lib_core.base.BaseEntity;
import com.google.gson.Gson;

import org.json.JSONArray;
import org.json.JSONException;

import java.util.ArrayList;
import java.util.List;

/**
 * 巡逻点实体
 * {
 "msg": "成功",
 "values": "[{\"pointId\":24,\"pointName\":\"大门\"}]",
 "statuesCode": "200"
 }
 * */
public class PointEntity extends BaseEntity{

    private String values;
    private List<Object>datas;

    public void setValues(String values) {
        this.values = values;
    }

    //获取全部巡更数据源->+到集合尾部
    public List<Object> getDatas() {
        datas = new ArrayList<>();
        try {
            JSONArray jsonArray = new JSONArray(values);
            for (int i = 0;i < jsonArray.length();i ++){
                String jsonStr = jsonArray.getJSONObject(i).toString();
                Values values = new Gson().fromJson(jsonStr,Values.class);
                datas.add(values);
            }
            Values values = new Values();
            values.pointName = "+";
            datas.add(values);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return datas;
    }

    public static class Values{
        public int pointId;
        public String pointName;
        public boolean isSelect = false;
    }

}
